home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Python 1.3.3 / Python 133 SRC / Tools / modulator / Templates / object_structure < prev    next >
Text File  |  1995-12-21  |  903b  |  43 lines

  1.  
  2. /* Code to access structure members by accessing attributes */
  3.  
  4. #include "structmember.h"
  5.  
  6. #define OFF(x) offsetof(XXXXobject, x)
  7.  
  8. static struct memberlist $abbrev$_memberlist[] = {
  9.     /* XXXX Add lines like { "foo", T_INT, OFF(foo), RO }  */
  10.  
  11.     {NULL}    /* Sentinel */
  12. };
  13.  
  14. static PyObject *
  15. $abbrev$_getattr(self, name)
  16.     $abbrev$object *self;
  17.     char *name;
  18. {
  19.     PyObject *rv;
  20.     
  21.     /* XXXX Add your own getattr code here */
  22.     rv = PyMember_Get((char *)/*XXXX*/0, $abbrev$_memberlist, name);
  23.     if (rv)
  24.         return rv;
  25.     PyErr_Clear();
  26.     return Py_FindMethod($abbrev$_methods, (PyObject *)self, name);
  27. }
  28.  
  29.  
  30. static int
  31. $abbrev$_setattr(self, name, v)
  32.     $abbrev$object *self;
  33.     char *name;
  34.     PyObject *v;
  35. {
  36.     /* XXXX Add your own setattr code here */
  37.     if ( v == NULL ) {
  38.         PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute");
  39.         return -1;
  40.     }
  41.     return PyMember_Set((char *)/*XXXX*/0, $abbrev$_memberlist, name, v);
  42. }
  43.